package com.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

import com.dao.PersonaDAO;
import com.modelo.Persona;

public class IPersonaDAO implements PersonaDAO {
	int retorno = 0;
	//@Resource PersonaDAO personaDao;
	//@Autowired PersonaDAO persona_Dao;
	
	private JdbcTemplate jdbcTemplate;
	
	
//	private @Autowired DataSource dataSource;
//	public void setDataSource(DataSource dataSource){
//		this.dataSource = dataSource;
//	}
//	public DataSource getDataSource(){
//		return this.dataSource;
//	}
	
	@Autowired
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
		this.jdbcTemplate = jdbcTemplate;
	}
	@Override
	public int insertar(Persona persona) {
		// TODO Auto-generated method stub
		System.out.println("IPersonaDAO insertar()");
		try{
			String sql = "INSERT INTO PERSONA " +
					"(NOMBRE, APELLIDO, DIRECCION, DNI) VALUES (?, ?, ?, ?)";
		 
			//jdbcTemplate = new JdbcTemplate(getDataSource());
		 
				jdbcTemplate.update(sql, new Object[] { persona.getNombre(),
					persona.getApellido(),persona.getDireccion(), persona.getDni()}); 
			
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return retorno;
	}
	@Override
	public Persona buscar(int id) {
		// TODO Auto-generated method stub
		return null;
	}

}
